
public class startseep {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		 boolean playAgain;       


		 do {
			 playseep();
			 TextIO.put("Play again? ");
			 playAgain = TextIO.getlnBoolean();
		 } while (playAgain);
		      

		
	}
	
	
	private static void playseep() {
		   
	      Deck deck = new Deck();  // Get a new deck of cards, and 
	                               //   store a reference to it in 
	                               //   the variable, deck.
	      
	      Card currentCard;  // The current card, which the user sees.

	            
	      deck.shuffle();  // Shuffle the deck into a random order before
	                       //    starting the game.

	      
	      
	            
	      Hand base = new Hand();
	      Hand one = new Hand();
	      
	      int high = 0;
	      do{
	    	  for (int i=0; i<4; i++) {
	        	  currentCard = deck.dealCard();
	        	  one.addCard(currentCard); 
	        	  if (currentCard.getValue()>8) {
	        		  high++;
	        	  }
	          }
	    	  if (high==0) {
	    		  deck.shuffle();
	    		  one.clear();
	    	  }
	      }while(high==0);
	      TextIO.putln("house cards - "+high);
	      
	      for (int i=0; i<4; i++) {
	    	  TextIO.put(one.getCard(i)+", ");
	      }
	      TextIO.putln();
	      
	      for (int i=0; i<4; i++) {
	    	  currentCard = deck.dealCard();
	    	  base.addCard(currentCard);    	  
	      }
	      
	      TextIO.putln("HIDDEN BASE CARDS");
	      for (int i=0; i<base.getCardCount(); i++) {
	    	  TextIO.put(base.getCard(i)+", ");
	      }
	      TextIO.putln("\n");
	      
	      
	      
	      for (int i=0; i<one.getCardCount(); i++) {
	    	  TextIO.putln(i+". "+one.getCard(i));
	      }

	      int bid;
	      ////////////////
	      do {
	    	  do{
	    	  TextIO.put("Bid for a House: ");
	    	  bid = TextIO.getInt();
	    	  }while(bid<0 || bid>3);
	    	  }while(one.getCard(bid).getValue()<9);
	      ////////////////////////
	      TextIO.putln("You have bid " + one.getCard(bid).getValueAsString());
	      
	      TextIO.putln("The base cards are - ");    
	      for (int i=0; i<base.getCardCount(); i++) {
	    	  TextIO.put(base.getCard(i)+", ");
	      }
	      TextIO.putln();
	      
	      int option;
	      TextIO.putln("0. Create a House");
	      TextIO.putln("1. Pick up Cards");
	      TextIO.putln("2. Throw down a Card");
	      option = TextIO.getInt();
	      
	      int bidhand;
	      int numbase;
	      int[] bidbase;
	      Card[] baseremove;
	      int bidtotal;
	      switch (option) {
	      case 0:
	    	  bidtotal = 0;
	    	  do {
	    		  TextIO.putln("Your Cards are:");
	        	  for (int i=0; i<one.getCardCount(); i++) {
	            	  TextIO.putln(i+". "+one.getCard(i));
	              }
	        	 
	        	  do {
	        		  TextIO.putln("Choose a card from your hand to add and create your bid house");
	            	  bidhand = TextIO.getInt();
	              }while(bidhand<0 || bidhand>3 || one.getCard(bidhand).getValue() >= one.getCard(bid).getValue());
	       
	        	  
	              TextIO.putln("The base cards are - ");    
	        	  for (int i=0; i<base.getCardCount(); i++) {
	            	  TextIO.putln(i+". "+base.getCard(i));
	              }
	     
	        	  do {
	        		  TextIO.putln("How MANY cards from base are needed to create your Bid House?");
	            	  numbase = TextIO.getInt();
	        	  }while(numbase<1 || numbase>4);
	        	      	  
	        	  bidbase = new int[numbase];
	        	  
	        	  do {
	        		  TextIO.putln("Choose a card from base to add and create your bid house");
	            	   bidbase[0] = TextIO.getInt();
	        	  }while(bidbase[0]<0 || bidbase[0]>3);
	        	 
	        	  for (int i=0; i<(numbase-1); i++) {
	        		  do {
	            		  TextIO.putln("Choose another card from base to add and create your bid house");
	                	  bidbase[i+1] = TextIO.getInt();
	                  }while(bidbase[i+1]<0 || bidbase[i+1]>3);
	        	  }
	    		  
	        	  for (int i=0; i<numbase; i++) {
	        		  bidtotal += base.getCard(bidbase[i]).getValue();
	        	  }
	        	  bidtotal += one.getCard(bidhand).getValue();

	        	  TextIO.putln("bidtotal = "+bidtotal+", bid = "+one.getCard(bid).getValue());
	        	  
	    	  }while(bidtotal != one.getCard(bid).getValue());
	    	  
	    	  TextIO.putln("You have successfully created a House of "+one.getCard(bid).getValueAsString()+"!");
	    	  one.removeCard(bidhand);
	    	  
	    	  TextIO.putln("Your Cards are:");
	    	  for (int i=0; i<one.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+one.getCard(i));
	          }
	    	  
	    	  baseremove = new Card[numbase];
	    	  for (int i=0; i<bidbase.length; i++) {
	    		  baseremove[i] = base.getCard(bidbase[i]);
	    	  }	  
	    	  for (int i=0; i<bidbase.length; i++) {
	    		  base.removeCard(baseremove[i]);
	    	  }
	    	  TextIO.putln("The base cards are - ");    
	    	  for (int i=0; i<base.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+base.getCard(i));
	          }
	    	  break;
	      case 1:
	    	  bidtotal = 0;
	    	  do {
	    		  
	    		  TextIO.putln("Your Cards are:");
	        	  for (int i=0; i<one.getCardCount(); i++) {
	            	  TextIO.putln(i+". "+one.getCard(i));
	              }
	        	 
	        	  do {
	        		  TextIO.putln("Choose a card from your hand to add and play your bid");
	            	  bidhand = TextIO.getInt();
	              }while(bidhand<0 || bidhand>3 || one.getCard(bidhand).getValue() != one.getCard(bid).getValue());
	        	  
	        	  TextIO.putln("The base cards are - ");    
	        	  for (int i=0; i<base.getCardCount(); i++) {
	            	  TextIO.putln(i+". "+base.getCard(i));
	              }
	        	  
	        	  do {
	        		  TextIO.putln("How MANY cards from base are needed to Play your Bid?");
	            	  numbase = TextIO.getInt();
	        	  }while(numbase<1 || numbase>4);
	        	      	  
	        	  bidbase = new int[numbase];
	        	  
	        	  do {
	        		  TextIO.putln("Choose a card from base to add and play your bid");
	            	   bidbase[0] = TextIO.getInt();
	        	  }while(bidbase[0]<0 || bidbase[0]>3);
	        	 
	        	  for (int i=0; i<(numbase-1); i++) {
	        		  do {
	            		  TextIO.putln("Choose another card from base to add and play your bid");
	                	  bidbase[i+1] = TextIO.getInt();
	                  }while(bidbase[i+1]<0 || bidbase[i+1]>3);
	        	  }
	        	  
	        	  for (int i=0; i<numbase; i++) {
	        		  bidtotal += base.getCard(bidbase[i]).getValue();
	        	  }

	        	  TextIO.putln("bidtotal = "+bidtotal+", bid = "+one.getCard(bid).getValue());
	        	  
	    	  }while(bidtotal != one.getCard(bid).getValue() && bidtotal/2 != one.getCard(bid).getValue() && bidtotal/4 != one.getCard(bid).getValue());

	    	  
	    	  TextIO.putln("You have successfully picked up "+one.getCard(bid).getValueAsString()+"!");
	    	  
	    	  one.removeCard(bidhand);
	    	  
	    	  baseremove = new Card[numbase];
	    	  for (int i=0; i<bidbase.length; i++) {
	    		  baseremove[i] = base.getCard(bidbase[i]);
	    	  }	  
	    	  for (int i=0; i<bidbase.length; i++) {
	    		  base.removeCard(baseremove[i]);
	    	  }
	    	      	  
	    	  TextIO.putln("Your Cards are:");
	    	  for (int i=0; i<one.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+one.getCard(i));
	          }
	    	  TextIO.putln("The base cards are - ");    
	    	  for (int i=0; i<base.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+base.getCard(i));
	          }
	    	  break;
	      case 2:
	    	  
	    	  TextIO.putln("Your Cards are:");
	    	  for (int i=0; i<one.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+one.getCard(i));
	          }
	    	 
	    	  do {
	    		  TextIO.putln("Choose a card from your hand to throw down");
	        	  bidhand = TextIO.getInt();
	          }while(bidhand<0 || bidhand>3 || one.getCard(bidhand).getValue() != one.getCard(bid).getValue());
	    	  
	    	  TextIO.putln("You have successfully thrown down "+one.getCard(bid).getValueAsString()+"!");

	    	  base.addCard(one.getCard(bidhand));
	    	  one.removeCard(bidhand);
	    	  
	    	  TextIO.putln("The base cards are - ");    
	    	  for (int i=0; i<base.getCardCount(); i++) {
	        	  TextIO.putln(i+". "+base.getCard(i));
	          }
	    	  
	    	  
	    	  break;
	      default:
	    	  break;
	      }
	      
	      TextIO.putln();
	      TextIO.putln("The game is over.");
	      
	}

}
